<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background:rgba(245,245,245,1);
            padding-bottom: 100px;
        }

        .vueApp {
            overflow: hidden;
        }

        .m-container-mod {
            margin: 15px;
            padding: 15px;
            background:rgba(255,255,255,1);
            box-shadow:0px 1px 8px 0px rgba(0,0,0,0.02);
            border-radius:8px;
        }

        .c-title {
            font-size:15px;
            font-weight:400;
            color:rgba(25,25,25,1);
            margin-bottom: 14px;
        }

        .c-radio {
            width: 22px;
            height: 22px;
            min-width: 22px;
            margin-right: 10px;
            margin-left: 40px;
            -webkit-appearance: none;
            background: url("../../image/ui/radio.png");
            background-size: 100% 100%;
        }

        .c-radio:first-child {
            margin-left: 0;
        }

        .c-radio:checked {
            background: url("../../image/ui/checked.png");
            background-size: 100% 100%;
        }

        .c-radio-txt {
            font-size:14px;
            font-weight:400;
            color:rgba(25,25,25,1);
        }

        .o-list-item {
            height: 50px;
        }

        .c-list-item-title {
            font-size:15px;
            font-weight:400;
            color:rgba(25,25,25,1);
            margin-right: 10px;
        }

        .c-list-item-input {
            height: 50px;
            text-align: right;
            font-size:15px;
            font-weight:400;
            color:rgba(25,25,25,1);
        }

        .c-list-item-input::placeholder {
            line-height: normal;
            font-size:15px;
            font-weight:400;
            color:rgba(191,191,191,1);
        }

        .c-border-bottom-less {
            position: relative;
        }

        .c-border-bottom-less::after {
            content: "";
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 1px;
            background-color: rgb(212,212,212);
            transform: scaleY(0.5);
        }

        .c-textarea {
            width: 100%;
            height: 73px;
            line-height: normal;
            font-size:15px;
            font-weight:400;
            color:rgba(25,25,25,1);
        }

        .c-textarea::placeholder {
            font-size:15px;
            font-weight:400;
            color:rgba(191,191,191,1);
            line-height: normal;
        }

        .c-tips {
            font-size:14px;
            font-weight:400;
            color:rgba(128,128,128,1);
        }

        .c-money-txt {
            width: 75px;
            font-size:15px;
            font-weight:400;
            color:rgba(25,25,25,1);
        }

        .c-money-count {
            font-size:20px;
            font-weight:400;
            color:rgba(25,25,25,1);
        }

        .c-money {
            height:20px;
            margin: 25px 15px 0 15px;
        }

        .btn {
            position: fixed;
            bottom: 0;
            width: 100%;
            height:50px;
            background:rgba(90,194,255,1);
            font-size:16px;
            font-weight:600;
            color:rgba(255,255,255,1);
        }
    </style>
</head>
<body>
    <div class="vueApp" v-cloak>
        <div class="m-container-mod">
            <div class="c-title">
                抬头类型
            </div>
            <div data-flex="cross:center">
                <input class="c-radio" type="radio" :checked="info.active == 2" @click="info.active = 2">
                <div class="c-radio-txt">企业单位</div>
                <input class="c-radio" type="radio" :checked="info.active == 1" @click="info.active = 1">
                <div class="c-radio-txt">个人/非企业单位</div>
            </div>
        </div>
        <div class="m-container-mod" style="padding-top: 0;padding-bottom: 0;">
            <div class="o-list-item  c-border-bottom-less" data-flex="main:justify cross:center">
                <div class="c-list-item-title">
                    {{ info.active === 2 ? '发票抬头' : '姓名' }}
                </div>
                <input class="c-list-item-input" v-show="info.active === 2" v-model="info.title" data-flex-box="1" type="text" placeholder="请输入发票抬头">
                <input class="c-list-item-input" v-show="info.active === 1" v-model="info.name" data-flex-box="1" type="text" placeholder="请输入姓名">
            </div>
            <div class="o-list-item  c-border-bottom-less" data-flex="main:justify cross:center">
                <div class="c-list-item-title">
                    {{ info.active === 2 ? '税号' : '身份证号' }}
                </div>
                <input class="c-list-item-input" v-show="info.active === 2" v-model="info.number" data-flex-box="1" type="text" placeholder="请输入税号">
                <input class="c-list-item-input" v-show="info.active === 1" v-model="info.idNum" data-flex-box="1" type="number" placeholder="请输入身份证号">
            </div>
            <div class="o-list-item" data-flex="main:justify cross:center">
                <div class="c-list-item-title">
                    接收邮箱
                </div>
                <input class="c-list-item-input" v-model="info.mailbox" data-flex-box="1" type="email" placeholder="请输入接受电子发票的邮箱">
            </div>
        </div>
        <div class="m-container-mod">
            <div class="c-title" data-flex="main:justify">
                <div>备注说明</div>
                <div class="c-tips">选填</div>
            </div>
            <textarea class="c-textarea" v-model="info.description" placeholder="请输入售后说明"></textarea>
        </div>
        <!-- <div class="m-container-mod" style="padding-top: 0;padding-bottom: 0;">
            <div class="o-list-item" data-flex="main:justify cross:center">
                <div class="c-list-item-title">
                    开户行和账号
                </div>
                <input class="c-list-item-input" v-model="" data-flex-box="1" type="text" placeholder="请填写开户行和账号">
            </div>
        </div> -->
        <div class="c-money" data-flex="main:right cross:center">
            <div class="c-money-txt">发票金额:</div>
            <div class="c-money-count">{{ info.money }}元</div>
        </div>
        <div class="btn" data-flex="main:center cross:center" @click="submitFn()">
            提交
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm;
    var pageParam = {};
    apiready = function(){
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        pageParam = api.pageParam;
        fnInit();
    };
    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                info: {
                    // 选中类型
                    active: 2,
                    // 发票抬头
                    title: '',
                    // 姓名
                    name: '',
                    // 身份证号
                    idNum: '',
                    // 税号
                    number: '',
                    // 邮箱
                    mailbox: '',
                    // 备注说明
                    description: '',
                    // 发票金额
                    money: pageParam.order.payAmount
                }
            }
        });
    }

    function submitFn() {
        if(vm.info.active === 2) {
            if(!vm.info.title || !vm.info.number || !vm.info.mailbox) {
                fnToast('不能有空的必填项');
                return;
            };
        } else if(vm.info.active === 1) {
            if(!vm.info.name || !vm.info.idNum || !vm.info.mailbox) {
                fnToast('不能有空的必填项');
                return;
            };
        };
        if(vm.info.active === 1 && !/^\d{17}([0-9]|X|x)$/.test(vm.info.idNum)) {
            fnToast('身份证输入错误');
            return;
        };
        if(vm.info.active === 2 && !/^(\w{15}|\w{18}|\w{20})$/.test(vm.info.number)) {
            fnToast('税号输入错误');
            return;
        };
        if(!/^[a-zA-Z0-9_-]+(\.|[a-zA-Z0-9_-]+)+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(vm.info.mailbox)) {
            fnToast('邮箱输入错误');
            return;
        };
        handleApply();
    }

    // 提交开票信息
    function handleApply() {
        var url = 'my/addOrderInvoice';
        var params = {
            orderSn: pageParam.order.orderSn,
            invoiceRiseType: vm.info.active,
            invoiceRise: vm.info.active === 1 ? vm.info.name : vm.info.title,
            taxNumber: vm.info.active === 1 ? vm.info.idNum : vm.info.number,
            invoiceEmail: vm.info.mailbox,
            remarks: vm.info.description,
            bank: '',
            bankAccount	: ''
        };
        var callback = function (data) {
            fnToast('提交成功');
            api.execScript({
                name: pageParam.refreshWin,
                frameName: pageParam.refreshFrm,
                script: 'fnOrderActionCallback();'
            });
           setTimeout(function() {
                api.closeWin();
           }, 500)
        };
        POST(url, params, callback);
    }
</script>
</html>